import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Posts, StatusContent } from '../posts/entities/post.entity';
import { Repository } from 'typeorm';
import { Category } from '../categories/entities/category.entity';
import { Tags } from '../tags/entities/tag.entity';
import { Comment, StatusComment } from '../comments/entities/comment.entity';
@Injectable()
export class SiteService {
  constructor(
    @InjectRepository(Posts)
    private postsRepository: Repository<Posts>,
    @InjectRepository(Category)
    private categoryRepository: Repository<Category>,
    @InjectRepository(Tags)
    private tagsRepository: Repository<Tags>,
    @InjectRepository(Comment)
    private commentRepository: Repository<Comment>,
  ) {}
  async findAll() {
    const data = {
      postsCount: 0,
      tagCount: 0,
      categoryCount: 0,
    };
    data.postsCount = await this.postsRepository.count({
      where: { status: StatusContent.Publish },
    });
    data.tagCount = await this.tagsRepository.count();
    data.categoryCount = await this.categoryRepository.count();
    return data;
  }

  async getInfo() {
    const data = {
      commentCount: 0,
    };
    data.commentCount = await this.commentRepository.count({
      where: { status: StatusComment.Pass },
    });
    return data;
  }
}
